import 'package:flustars/flustars.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:wallet_home/page/theme/styles.dart';
import 'package:wallet_home/tools/common.dart';
import 'package:wallet_home/tools/theme_utils.dart';

import 'colors.dart';

//extension ThemeModeExtension on ThemeMode {
//  String get value => ["system", "light", "dark"][index];
//}

class ThemeProvider extends ChangeNotifier {
  String theme = "system";

  void setTheme(String themeMode) {
    this.theme = themeMode;
//    Tools.themeType = themeMode.value;
    notifyListeners();
  }

  ThemeMode getThemeMode() {
    // String theme = SpUtil.getString(Constant.themeModel);
    ThemeMode themeMode;
    if (theme == null) {
      theme = SpUtil.getString(Constant.themeModel);
    }
    switch (theme) {
      case "light":
        themeMode = ThemeMode.light;
        break;
      case "dark":
        themeMode = ThemeMode.dark;
        break;
      default:
        themeMode = ThemeMode.system;
        break;
    }
    return themeMode;
  }

  //Dark和Light模式
  ThemeData getTheme({bool isDarkMode = false}) {
    print("dark============light=====$isDarkMode");
    if(SpUtil.getString(Constant.themeModel).isEmpty){
      theme = "system";
    }else{
      theme = SpUtil.getString(Constant.themeModel);
    }
    return ThemeData(
      errorColor: isDarkMode ? Colours.dark_red : Colours.red,
      brightness: isDarkMode ? Brightness.dark : Brightness.light,
      primaryColor: isDarkMode ? Colours.dark_app_main : Colours.app_main,
      accentColor: isDarkMode ? Colours.dark_app_main : Colours.app_main,
      indicatorColor: isDarkMode ? Colours.dark_app_main : Colours.app_main,
      scaffoldBackgroundColor:
          isDarkMode ? Colours.dark_bg_color : Colors.white,
      canvasColor: isDarkMode ? Colours.dark_material_bg : Colors.white,
      textSelectionColor: Colours.app_main.withAlpha(70),
      textSelectionHandleColor: Colours.app_main,
      textTheme: TextTheme(
        subtitle1: isDarkMode ? TextStyles.textDark : TextStyles.text,
        bodyText2: isDarkMode ? TextStyles.textDark : TextStyles.text,
        subtitle2:
            isDarkMode ? TextStyles.textDarkGray12 : TextStyles.textGray12,
      ),
      inputDecorationTheme: InputDecorationTheme(
          hintStyle:
              isDarkMode ? TextStyles.textHint14 : TextStyles.textDarkGray14),
      appBarTheme: AppBarTheme(
        //  color: isDarkMode ? Colours.dark_bg_color : Colors.white,
        textTheme: TextTheme(
          headline6: TextStyle(
              color: isDarkMode ? Colors.white : Colors.white, fontSize: 18),
          bodyText1: TextStyle(color: isDarkMode ? Colors.white : Colors.black),
          bodyText2: TextStyle(color: isDarkMode ? Colors.white : Colors.black),
        ),
        iconTheme:
            IconThemeData(color: isDarkMode ? Colors.white : Colors.white),
        color: isDarkMode ? Colors.grey[800] : Colours.app_main,
//          brightness: isDarkMode ? Brightness.dark : Brightness.dark
      ),
      dividerTheme: DividerThemeData(
        color: isDarkMode ? Colors.grey[400] : Colors.grey[200],
      ),
      cupertinoOverrideTheme: CupertinoThemeData(
          brightness: isDarkMode ? Brightness.dark : Brightness.light),
      cardColor: isDarkMode ? Colors.grey[850] : Colors.white,
      cursorColor: isDarkMode ? Colors.white : Colors.grey[400]
    );
  }
}
